﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MCSFramework.Model.TEST;
using System.Data.SqlClient;
using MCSFramework.DBUtility;
using System.Data;

namespace MCSFramework.SQLDAL.TEST
{
    public class TEST_ClientDAL : BaseSimpleDAL<TEST_Client>
    {

        public TEST_ClientDAL()
        {
            _ProcePrefix = "MCS_TEST.dbo.sp_TEST_Client";
        }

        protected override TEST_Client FillModel(System.Data.IDataReader dr)
        {
            TEST_Client m = new TEST_Client();

            if (!string.IsNullOrEmpty(dr["ID"].ToString())) m.ID = (int)dr["ID"];
            if (!string.IsNullOrEmpty(dr["Name"].ToString())) m.Name = (string)dr["Name"];
            if (!string.IsNullOrEmpty(dr["TeleNum"].ToString())) m.TeleNum = (string)dr["TeleNum"];
            if (!string.IsNullOrEmpty(dr["Mobile"].ToString())) m.Mobile = (string)dr["Mobile"];
            if (!string.IsNullOrEmpty(dr["Fax"].ToString())) m.Fax = (string)dr["Fax"];
            if (!string.IsNullOrEmpty(dr["Address"].ToString())) m.Address = (string)dr["Address"];
            if (!string.IsNullOrEmpty(dr["PostCode"].ToString())) m.PostCode = (string)dr["PostCode"];
            if (!string.IsNullOrEmpty(dr["Prov"].ToString())) m.Prov = (string)dr["Prov"];
            if (!string.IsNullOrEmpty(dr["City"].ToString())) m.City = (string)dr["City"];
            if (!string.IsNullOrEmpty(dr["Inserttime"].ToString())) m.Inserttime = (DateTime)dr["Inserttime"];

            return m;
        }

        public override int Add(TEST_Client m)
        {
            SqlParameter[] parameter ={
                                     //SQLDatabase.MakeInParam("ID",SqlDbType.Int,4,m.ID),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Name",SqlDbType.VarChar,20,m.Name),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("TeleNum",SqlDbType.VarChar,20,m.TeleNum),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Mobile",SqlDbType.VarChar,20,m.Mobile),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Fax",SqlDbType.VarChar,20,m.Fax),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Address",SqlDbType.VarChar,20,m.Address),                    
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("PostCode",SqlDbType.VarChar,20,m.PostCode),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Prov",SqlDbType.VarChar,20,m.Prov),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("City",SqlDbType.VarChar,20,m.City),
                                     };
            int ret = SQLDatabase.RunProc(_ProcePrefix + "_Add", parameter);
            return ret;
        }

        public override int Update(TEST_Client m)
        {
            SqlParameter[] parameter ={
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("ID",SqlDbType.Int,4,m.ID),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Name",SqlDbType.VarChar,20,m.Name),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("TeleNum",SqlDbType.VarChar,20,m.TeleNum),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Mobile",SqlDbType.VarChar,20,m.Mobile),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Fax",SqlDbType.VarChar,20,m.Fax),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Address",SqlDbType.VarChar,20,m.Address),                    
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("PostCode",SqlDbType.VarChar,20,m.PostCode),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("Prov",SqlDbType.VarChar,20,m.Prov),
                    MCSFramework.DBUtility.SQLDatabase.MakeInParam("City",SqlDbType.VarChar,20,m.City),
                                     };
            int ret = SQLDatabase.RunProc(_ProcePrefix + "_Update", parameter);
            return ret;
        }
    }
}
